#ifndef JSONRPCSERVER_H
#define JSONRPCSERVER_H


#include <QObject>
#include <QMap>

#include "jsonrpcmessage.h"

class QIODevice;
class JsonRpcService;

/**
 * @brief The JsonRpcServer class is a server that declares all the services that user will be able to use by storing a pointer to a JsonRpcService. It also stores the client sockets that are connected
 * to the server to potentially send a notification to them. When a client is disconnected of the server, it is removed from the list of clients
 */
class JsonRpcServer : public QObject
{
    Q_OBJECT
public:

    void addService(JsonRpcService* service);


protected Q_SLOTS:
    virtual void connectClient() = 0;
    virtual void disconnectClient() = 0;

    void processJsonRpcMessage(const JsonRpcMessage& message);
    void notify(const QString& methodName, const QVariantList& params);

protected:
    void insertClient(QIODevice *device, JsonRpcSocket *socket);
    void removeClient(QIODevice *device);


protected:
    QMap<QIODevice*, JsonRpcSocket*> v_clientSocketMap;

private:
    QMap<QString, JsonRpcService*> v_serviceMap;
};

#endif // JSONRPCSERVER_H
